Skip to content

feat(lk): write evals and session labels under --user-auth - #1153

Merged
jmcclanahan merged 25 commits into
mainfrom
jakemcclanahan/eval-writes
Dec 2, 2026
Merged

jmcclanahan merged 25 commits into
mainfrom
jakemcclanahan/eval-writes

Conversation

@jmcclanahan

@jmcclanahan jmcclanahan commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Stacked on #1152 (eval reads). Merge order: #1152 → this.

What

Lets a person or coding agent signed in with --user-auth write and ship evals from lk: check a definition, create an eval, save a draft, publish it, roll it back. It also manages session labels (the intents and outcomes an LLM assigns to each session).

  • lk agent eval validate | create | update | save | discard | publish | rollback | delete | undelete
  • lk agent eval defaults set --file FILE (the project's judge defaults)
  • lk agent eval label create | update | delete | undelete, lk agent eval label settings set
  • Definitions come from --file FILE (or - for stdin), a JSON object, the same one get --json prints

Why

The Public API's EvalService writes are in production (livekit/public-api-server#212, livekit/public-api-server#213), but lk could only read evals (#1152). Authoring from a file makes evals scriptable, and a coding agent can edit them.

How

  • Asks before paid work: publish, rollback, undelete and label create/undelete start LLM judging or labeling, so they ask first, matching the MCP tools' confirm: true. Discard asks too, since the draft is lost. --yes skips the question; a run that can't prompt refuses and sends nothing. The question helper moved to utils.go, and member removal uses it too.
  • Draft etags: save sends only the --etag it is given, so it never replaces a draft the caller didn't read; without one, the API accepts the save only when the eval has no draft. publish and discard show who last changed the draft and when in their question, and --yes needs --etag. A stale etag (Aborted) says how to re-read; a stale base revision (FailedPrecondition) prints the diff to run and --allow-stale-base. To tell the two apart, APIError now keeps the envelope's gRPC code.
  • Field violations: a refused definition lists each wrong field under the message. FieldViolations and the cloudAPIError change are copied from feat(lk): lk agent builder manages Agent Builder agents under --user-auth #1136; whichever merges second takes one copy, and lines its permission errors up with feat(lk): lk agent builder manages Agent Builder agents under --user-auth #1136's cloudOnlyAPIError.
  • Settings merge: label settings set reads the settings, changes only the flags given, and sends them all, because the API resets any field left out.
  • Definitions verbatim: a definition goes up as written, never through the generated type. A whole get --json response is refused, with the jq that extracts the definition.

Testing

  • go build ./..., go vet ./..., go test ./... and go test -race ./cmd/lk ./pkg/public/... pass.
  • Unit tests cover each request body, including unknown definition fields surviving, the etag and stale-base paths, the refusals without --yes, the violations listing, and the settings merge.
  • New testscript eval-writes-with-user-auth.txtar runs the binary through validate, create, save, publish (refused without --yes, then with it), label create and settings set. The request log shows that a refused change sends nothing.
  • Ran create, update, save, diff and publish on staging (the evals seed project).
  • Not yet run on staging: delete, undelete, rollback and the label writes.

🤖 Generated with Claude Code

Topherhindman and others added 11 commits November 24, 2026 14:00
Picks up the Public API's project-level observability reads:
ListProjectLogs, ListLogPatterns and GetAgentInsights. Nothing calls
them yet.

Also picks up what the spec gained since the last regeneration: the
eval and session label RPCs, GetSessionEvals, ListEvalSessions,
GetEvalResults, GetSessionLabelResults, and Agent Builder, whose
service is now AgentBuilderService in place of BuilderAgentService.
Nothing in lk calls them.

Generated from livekit/public-api-server@16e4400
Reads the Public API's ListProjectLogs: the log records that the logs
page on the dashboard lists, from the project's agents, client SDKs and
LiveKit, newest first, one line per record with its time, level,
source, session, logger and message. --json prints the records as the
API sends them.

--since, or --start and --end (a UTC date or an RFC 3339 time), set the
range; without them the server reads the last 24 hours. --log-level,
--source, --session-id and --query filter, --sort-order orders, and
--limit and the hidden --cursor page, as for lk analytics session logs.

The read is for project admins. A refusal says so, a query the server
can't parse gets a hint about the search syntax (an attribute needs its
@), and with user data recording off the error names the settings page,
as the session reads do.
Reads the Public API's ListLogPatterns: the patterns that the logs page
on the dashboard groups a project's log records into, ranked, one row
each with its number of records, level, source, first and last record,
and template. A note on stderr says how many records the range holds
and, on a project with many records, that the counts are estimates.
--json prints the API's response, with each pattern's counts over time
and its variants.

It takes the same range flags as lk analytics logs, plus --min-level
(the server's default is WARN), --source agent|client, --agent-name,
--agent-id, --session-id, --query, --rank events|first-seen|last-seen
and --limit. The list is one page, so there is no --cursor.

The read is for project admins, and its errors say so as the logs'
do.
Reads the Public API's GetAgentInsights: the data that the agent
dashboards of LiveKit Cloud show, as four tables. The totals; the
latencies that have measurements (end-to-end, LLM and realtime time to
first token, TTS time to first byte, transcription and end-of-utterance
delay, tool calls) with p50, p95, p99, mean and max; one row for each
agent and deployment, busiest first; and one row for each model, with
its tokens, characters or seconds of audio. --json prints the API's
response.

It takes the same range flags as lk analytics logs, reading the last 7
days by default, and --agent-id and --agent-name, repeatable, to select
agents. Every project member can read it, so a refusal says the caller
has no access to the project rather than that it needs an admin.
- A project read's refusal now goes through readAPIError, which
  sessionAPIError also calls, so the two no longer repeat the same
  permission-denied wording.
- The help says that a lone --end moves the range too: each read covers
  its default length before --end. It also says that times print in
  local time.
- The hint for a query the server can't parse no longer says that a
  missing @ is the only cause.
- logs' usage line lists --sort-order and --limit, and --source's help
  gives a participant joining as its platform example, the proto's
  own example.
- log-patterns prints "1 pattern shown", not "1 patterns".
- insights prints a dash for an STT's requests, which the API always
  counts as 0.
Adds client calls for the Public API's eval reads: ListEvals, GetEval,
ListEvalHistory, DiffEvalRevisions, GetEvalDefaults, ListSessionLabels,
GetSessionLabelSettings, GetEvalResults, GetSessionLabelResults,
ListEvalSessions and GetSessionEvals, with their renderers.

GetEval and GetEvalDefaults keep the definition as the API sent it: the
generated type drops unknown properties and stores pass_threshold as a
float32.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
lk agent eval list|get|history|diff|defaults and lk agent eval label
list|settings read a project's evals and session labels. lk analytics
evals|eval-sessions|labels and lk analytics session evals read their
results.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Adds client calls for the Public API's eval writes: ValidateEval,
CreateEval, UpdateEval, SaveEvalDraft, DiscardEvalDraft,
PublishEvalDraft, RollbackEval, DeleteEval, UndeleteEval,
UpdateEvalDefaults, the session label writes and
UpdateSessionLabelSettings. Definitions go to the API verbatim.

APIError now keeps the error envelope's gRPC code, so a caller can tell a
stale draft etag (Aborted) from a stale base revision
(FailedPrecondition), and FieldViolations reads a BadRequest detail.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Adds lk agent eval validate|create|update|save|discard|publish|rollback|
delete|undelete, lk agent eval defaults set, lk agent eval label
create|update|delete|undelete and lk agent eval label settings set.

Publish, rollback, undelete and label create/undelete start LLM judging
or labeling, so they ask first, as the MCP tools do; discard asks too.
--yes skips the question, and a run that can't ask refuses. A refused
request lists the fields the API named.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Six agent dev tests left devSession.run running after they returned. It
prints through the shared out, so it raced with the next test that
replaced out; the new agent_eval_test.go sorts right after them and
tripped -race.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jmcclanahan
jmcclanahan added this pull request to stack #1154 December 1, 2026 17:50
@jmcclanahan
jmcclanahan marked this pull request as ready for review December 1, 2026 18:40
devin-ai-integration[bot]

This comment was marked as resolved.

jmcclanahan and others added 9 commits December 1, 2026 14:34
Print the reason on its own lines wrapped at 80 columns and the transcript
excerpt quoted with "> " as written, not Go-quoted. Leave "on -" out of an
eval heading when the session has no agent name.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The eval sessions response carries only the label IDs, so read the project's
labels (deleted ones included) once and show each label by name. A failed
label read falls back to the IDs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
lk analytics eval-sessions reads the project's evals once and shows each eval
by name, cut to 30 characters, falling back to the ID. lk analytics session
evals prints a blank line between one eval's failures and the next eval.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A flag given with a blank ID used to read every session, as if it were left out.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
An explicit empty --etag now reaches the API, which refuses the save when a
draft exists, instead of the CLI adopting the current draft's etag. A
definition file holding null is refused like any other non-object.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@Topherhindman Topherhindman left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

took a pass at f846300. the etag default is the main thing (inline). small: FieldViolations is the same code as #1136, and #1136's cloudOnlyAPIError covers what the three IsPermissionDenied branches here hand-roll, so worth lining those up when one of them lands. on the body: the bare #212/#213 want livekit/public-api-server#N, and the "Draft etags" paragraph describes the auto-read as a feature, which would change with the etag comment

Comment thread cmd/lk/agent_eval_writes.go Outdated
return evalWriteError(err, projectID, evalID)
}
if draft != nil {
etag = util.Deref(draft.DraftEtag)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

without --etag this reads the current etag and sends it, so save always wins and quietly replaces whatever draft a teammate saved. agent-evals refuses an empty etag when a draft exists on purpose. could save just send what --etag gave, and let the Aborted hint point at get --draft --json?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 6c1a5df: save sends only what --etag gives, and prints the new draftEtag. The Aborted hint points at get --draft --json.

evalID, util.Accented("lk agent eval save "+evalID+" --file FILE"))
}
if p.Etag == "" {
p.Etag = util.Deref(draft.DraftEtag)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here and in discard: the prompt is the only guard, and --yes skips it. should --yes require --etag, or at least the prompt say who saved the draft and when?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both, in 6c1a5df: --yes needs --etag, and the prompt shows when the draft last changed and by whom.

Comment thread cmd/lk/agent_eval_writes.go Outdated
}
got, err := client.PublishEvalDraft(ctx, projectID, evalID, p.EvalPublishOptions)
if err != nil {
if public.IsFailedPrecondition(err) && len(public.FieldViolations(err)) == 0 {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

publishing a deleted eval's draft lands here too ("the eval is deleted" is a FailedPrecondition with no violations), and then points at diff + --allow-stale-base. you already have draft.BaseRevision and e.PublishedRevision, could the hint only show when they differ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 6c1a5df: the hint shows only when the base isn't live.

Comment thread cmd/lk/agent_eval_writes.go Outdated
// judging or labeling, or loses work: title is the question, and description
// says what follows. yes (--yes) confirms without asking; a run that can't
// ask fails with refusal and a hint to pass --yes.
func confirmEvalChange(ctx context.Context, yes bool, title, description, refusal string) error {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is confirmKeyDeletion from member_removal.go with the strings passed in. could it move to utils.go and member_removal use it, instead of a second copy?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 6c1a5df: confirmAction in utils.go, used by member removal too.

Comment thread cmd/lk/agent_eval_writes.go Outdated
// flags.
func labelSettingsFlags() []cli.Flag {
return []cli.Flag{
&cli.FloatFlag{Name: "confidence-threshold", Usage: "Lowest confidence `N`, above 0 and at most 1, at which the LLM keeps a label (default 0.7)"},

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

help prints (default 0.7) (default: 0) here and (default 1) (default: 0) on --min-user-turns. HideDefault: true like --revision?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 6c1a5df.

func createEval(ctx context.Context, client *public.Client, projectID string, c evalCreate, asJSON bool) error {
got, err := client.CreateEval(ctx, projectID, c.name, c.description, c.definition)
if err != nil {
return evalWriteError(err, projectID, "")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a NotFound on create is the project, so this prints "(eval in project p_…)". same on label create. projectReadError instead?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 6c1a5df: NotFound on create now goes through projectReadError.

Comment thread pkg/public/eval_writes.go

// decodeOK decodes a 200 response's body into out, and returns the API's
// error for any other status.
func decodeOK(status int, body []byte, out any) error {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: GetEval and GetEvalDefaults in evals.go inline this same block, could they use it?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 6c1a5df.

jmcclanahan and others added 4 commits December 1, 2026 17:03
…eads

# Conflicts:
#	cmd/lk/analytics.go
#	cmd/lk/analytics_project.go
#	cmd/lk/analytics_project_test.go
#	cmd/lk/script_test.go
#	pkg/public/project_logs.go
#	pkg/public/project_logs_test.go
- sessionRead and evalAction share one actionWithID, which takes the ID's name.
- eval-sessions and the eval results reads share the agent, intent and outcome
  filter flags.
- Drop the client's copy of the criterion rules; the API refuses a criterion
  without its eval or with a verdict.
- The eval-sessions usage shows --verdict works without --eval-id.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- save sends only the draftEtag that --etag gives, so it never replaces a draft
  the caller didn't read; it prints the new draftEtag for the next change.
- publish and discard: --yes needs --etag, and the question says when the draft
  last changed and who changed it.
- publish points at --allow-stale-base only when the draft's base isn't live.
- create and label create report a NotFound as the project's, not an empty eval's.
- One confirmAction in utils.go for the eval commands and member removal.
- GetEval and GetEvalDefaults decode through decodeOK.
- label settings set prints each default once.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@Topherhindman Topherhindman left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, checked the etag change on the wire: save sends nothing it wasn't given and --yes needs --etag. one optional thing: the recipe in the help ends with a publish that a script can't run without --yes --etag, could add save --json's draftEtag there. approving

Base automatically changed from jakemcclanahan/eval-reads to main December 2, 2026 01:44
…rites

# Conflicts:
#	cmd/lk/agent_eval.go
#	cmd/lk/script_test.go
#	pkg/public/evals.go
#	pkg/public/render/evals.go
@jmcclanahan
jmcclanahan merged commit ff0e4d1 into main Dec 2, 2026
27 checks passed
@jmcclanahan
jmcclanahan deleted the jakemcclanahan/eval-writes branch December 2, 2026 02:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants